from typing import List

from afast_core.core_tools import json_helper
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.services.service_businesses import \
    Businesses



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    pass
    appid:str
    si_number:str
    dc_number:str
    rulesid:str
    workcycle:List[str]
    worktab:str
    interval_am_sart:str
    interval_am_end:str
    interval_days: int
    interval_pm_sart: str
    interval_pm_end: str
    interval_scheduling_stock: int
    interval_time:int
    rulesname:str
    is_opened:int =1
    status:int =1

class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class DoctorStationRuleInfoUpdateController(IController):

    def business_login(self):
        pass
        order = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        self.schema_param.workcycle = sorted(list(set(self.schema_param.workcycle)), key=lambda x: order.index(x))
        updata = {
            'rulesname':self.schema_param.rulesname,
            'mode_workcycle_rules':json_helper.dict_to_json(self.schema_param.dict(include={'interval_am_sart',
                                                                                            'interval_am_end',
                                                                                            'interval_days',
                                                                                            'interval_pm_sart',
                                                                                            'interval_pm_end',
                                                                                            'interval_scheduling_stock',
                                                                                            'interval_time',
                                                                                            'workcycle'
                                                                                            }))
        }

        # 更新规则记录信息
        Businesses.update_doctor_station_rule_info(rulesid=self.schema_param.rulesid, **updata)
        # 更新医馆的状态字段信息
        Businesses.update_doctor_station_rule_info_and_doctorstation(
            appid=self.schema_param.appid,
            si_number=self.schema_param.si_number,
            dc_number=self.schema_param.dc_number,
            is_opened =1 if self.schema_param.is_opened else 0,
            status=1 if self.schema_param.status else 0,
        )
        # sorted_data = sorted(data)
        self.response_msg='更新成功！'
        return



